﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace MathTest
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.textBox1.Text = "";
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "MDF files(*.EXE)|*.EXE|All files(*.*)|*.*";
            dialog.ShowDialog();
            if (this.textBox1.Text == string.Empty)
            {
                this.textBox1.Text = dialog.FileName;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.textBox2.Text = "";
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "EXE files(*.EXE)|*.EXE|All files(*.*)|*.*";
            dialog.ShowDialog();
            if (this.textBox2.Text == string.Empty)
            {
                this.textBox2.Text = dialog.FileName;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            ProcessStartInfo psi = new ProcessStartInfo(this.textBox2.Text);
            Process.Start(psi);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string str = this.textBox1.Text.Substring(this.textBox1.Text.LastIndexOf(@"\") + 1);
            str = str.Substring(0, str.LastIndexOf("."));

            Process[] process = Process.GetProcessesByName(str);
            foreach (var item in process)
            {
                item.Kill();
            }
        }
    }
}
